"""
监控指标模型
"""
from sqlalchemy import Column, Integer, String, Float, DateTime, Text, Boolean
from sqlalchemy.sql import func
from app.models.base import Base

class Metric(Base):
    """监控指标表模型"""
    __tablename__ = 't_metrics'
    
    id = Column(Integer, primary_key=True, autoincrement=True, comment='指标ID')
    machine_id = Column(Integer, nullable=False, comment='机器ID')
    cpu_percent = Column(Float, nullable=True, comment='CPU使用率(%)')
    cpu_count = Column(Integer, nullable=True, comment='CPU核心数')
    cpu_count_logical = Column(Integer, nullable=True, comment='CPU逻辑核心数')
    cpu_freq_current = Column(Float, nullable=True, comment='CPU当前频率(MHz)')
    memory_total = Column(Integer, nullable=True, comment='总内存(字节)')
    memory_available = Column(Integer, nullable=True, comment='可用内存(字节)')
    memory_percent = Column(Float, nullable=True, comment='内存使用率(%)')
    memory_used = Column(Integer, nullable=True, comment='已用内存(字节)')
    swap_total = Column(Integer, nullable=True, comment='交换空间总大小(字节)')
    swap_used = Column(Integer, nullable=True, comment='已用交换空间(字节)')
    swap_percent = Column(Float, nullable=True, comment='交换空间使用率(%)')
    disk_info = Column(Text, nullable=True, comment='磁盘信息(JSON格式)')
    network_bytes_sent = Column(Integer, nullable=True, comment='网络发送字节数')
    network_bytes_recv = Column(Integer, nullable=True, comment='网络接收字节数')
    network_packets_sent = Column(Integer, nullable=True, comment='网络发送包数')
    network_packets_recv = Column(Integer, nullable=True, comment='网络接收包数')
    timestamp = Column(DateTime, nullable=False, default=func.now(), comment='时间戳')
    created_at = Column(DateTime, nullable=False, default=func.now(), comment='创建时间')
    updated_at = Column(DateTime, nullable=False, default=func.now(), onupdate=func.now(), comment='更新时间')